# -*- coding: utf-8 -*-
class BaseSelectCanvas:
    def __init__(self):
        self.drawDefName = ""

    def getTitle(self):
        """ 获取标题 """
        return "Unknow"

    def onCreate(self):
        pass

    def onDestroyBefore(self):
        pass

    def dyBind(self, uiNode, targetPath=""):
        """ 动态绑定UI节点 """
        pass

class CustomMainSetCanvas(BaseSelectCanvas):
    """ 自定义的游戏设置画布 """
    _CACHE_ALL_CHILD_NAME = []

    class SelectHandler:
        RELOAD_ALL = -1
        def __init__(self):
            pass

        def getRenderText(self):
            """ 获取渲染文本 """
            return "Unknow"
        
        def getRenderState(self):
            """ 获取渲染状态 """
            return False
        
        def onClick(self):
            """ 点击事件 若返回True则表示处理了点击事件需要更新渲染 """
            return False

        def setNeedUpdateSave(self):
            """ 设置需要更新保存数据 """
            pass

    class ButtonHandler(SelectHandler):
        def __init__(self, title, bindFunc=lambda: None):
            CustomMainSetCanvas.SelectHandler.__init__(self)
            self.title = title
            self.bindFunc = bindFunc
        
        def onClick(self):
            self.bindFunc()
        
        def getRenderText(self):
            return self.title
        
        def getRenderState(self):
            return False

    class BaseRender:
        def __init__(self):
            self.useChild = ""
            self._mallocUpdate = lambda: None
            self._updateOnceView = lambda: None
            self._updateAllView = lambda: None

        def getDoc(self):
            return "Unknow"

        def setNeedUpdate(self):
            """ 设置需要更新界面 """
            return self._mallocUpdate()

        def setUpdateOnceView(self):
            """ 设置需要更新单一视图 """
            return self._updateOnceView()
        
        def setUpdateAllView(self):
            """ 设置需要更新所有视图 """
            return self._updateAllView()
    
        def onCreate(self):
            pass

        def getTargetPanel(self):
            return ""
        
        def getTargetPanelObj(self):
            pass

    class Title(BaseRender):
        def __init__(self, title=""):
            CustomMainSetCanvas.BaseRender.__init__(self)
            self.useChild = "title"
            self.title = title

        def onCreate(self):
            pass

    class Select(BaseRender):
        def __init__(self, bindObjs=[]):
            # type: (list[CustomMainSetCanvas.SelectHandler]) -> None
            CustomMainSetCanvas.BaseRender.__init__(self)
            self.useChild = "select"
            self.bindObjs = bindObjs[::]

        def onCreate(self):
            pass

        def updateRender(self, buttonPath="", index=0):
            """ 更新渲染 """
            pass

    class Button(Select):
        def __init__(self, title="按钮", bindFunc=lambda: None):
            CustomMainSetCanvas.Select.__init__(self, [
                CustomMainSetCanvas.ButtonHandler(title, bindFunc)
            ])

    def __init__(self, targetList=[], bindQuery=0, title="基础设置"):
        BaseSelectCanvas.__init__(self)
        self.drawDefName = ""
        self.targetList = targetList[::]    # type: list[CustomMainSetCanvas.BaseRender]
        self.renderBinder = None
        self.updateRenderIng = False
        self.needUpdate = False
        self.title = title
        self.bindQuery = bindQuery

    def getTitle(self):
        return self.title

    def onCreate(self):
        pass

    def updateTargetList(self, newTargetList=[]):
        pass

    def updateBefore(self):
        pass

    def updateFinish(self):
        pass

    def renderViewUpdate(self, viewPath="", index=0):
        """ 渲染视图更新 """
        pass

    def setNeedUpdate(self):
        pass

class PageRegistry:
    """ 注册相关功能推荐在MOD加载完毕事件下进行 """
    @staticmethod
    def registerPage(page):
        # type: (BaseSelectCanvas) -> bool
        """ 注册自定义页面 """
        return False

    @staticmethod
    def addBasicSetting(render):
        # type: (BaseSelectCanvas.BaseRender) -> bool
        """ 追加注册基础设置页面的渲染内容(必须在OnLocalPlayerStopLoading之前完成后续会被冻结注册表) """
        return False